package cn.jsu.oj.dispatchServer.satellite.config;

import lombok.extern.slf4j.Slf4j;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

import java.util.concurrent.ExecutorService;

/**
 * 心跳配置
 *
 * @author shan
 * @date 2022/06/29
 */
@Slf4j
@Configuration
@DependsOn("executorService")
public class HeartConfig {

    @Autowired
    ExecutorService executorService;

    /**
     * 注册调度器bean
     *
     * @return {@link Scheduler }
     */
    @Bean("scheduler")
    Scheduler initScheduler() {
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = null;
        try {
            scheduler = schedulerFactory.getScheduler();
            scheduler.start();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
        log.info("bean: 调度器配置完成，等待调度工作......");
        return scheduler;
    }
}
